<% @page_title = "Search book" %>
<%= stylesheet_link_tag "admin/form", :media => "all" %>
<%= stylesheet_link_tag "admin/list-items", :media => "all" %>

<div class="search-form">
	<h1>Search book</h1>
	<%= form_tag({:controller => "admin/book", :action => "search"}, :method => 'get') do |f| %>
	<p>
		<%= text_field_tag(:keyword) %>&nbsp;
		<%= select_tag(:cate, options_for_select([['ID', 0], ['Title', 1], ['Author', 2], ['Category', 3], ['Publisher', 4], ['Price', 5], ['Quantity', 6], ['Free Quantity', 7]], -1)) %>&nbsp;
		<%= submit_tag "Search", :name => 'search' %>
	</p>
	<% end %><!-- End form -->
</div><!-- End .search-form -->

<% if @results_list %>
<div class='search-result' style='margin-top: 30px'>
	<h1>Results</h1>
	<% if @results_list.size > 0 %>
		<table>
			<tr>
				<th>ID</th>
				<th>Title</th>
				<th>Author</th>
				<th>Category</th>
				<th>Publisher</th>
				<th>Price</th>
				<th>Quantity</th>
				<th>Free quantity</th>
				<th class='action'>Action</th>
			</tr>
			<% order = 0 %>
			<% @results_list.each do |book| %>
				<tr <% if order % 2 == 0 %><%= "class='alt'" %><% end %> ><% order += 1 %>
					<td class='id'><%= book.id %></td>
					<td><%= link_to book.title, :controller => "admin/book", :action => "view", :id => book.id %></td>
					<td><%= book.author %></td>
					<td><%= BookCategory.getBookCateName(book.book_category_id) %></td>
					<td><%= book.publisher %></td>
					<td><%= book.price %></td>
					<td><%= book.quantity %></td>
					<td><%= book.free_quantity %></td>
					<td class='action'>
						<%= link_to image_tag('icons/view-icon.png'), :controller => "admin/book", :action => "view", :id => book.id %>&nbsp;
						<%= link_to image_tag('icons/edit-icon.png'), :controller => "admin/book", :action => "edit", :id => book.id %>&nbsp;
						<%= link_to image_tag('icons/delete-icon.png'), {:controller => "admin/book", :action => "delete", :id => book.id}, :method => "delete", :data => {:confirm => "Are you sure?"} %>
					</td>
				</tr>
			<% end %>
		</table>
		<div class='paginator' style='margin-left:100px'><%= will_paginate @results_list %></div>
	<% else %>
		<h3 style='color: red'>No result found</h3>
	<% end %>
</div><!-- End .search-result -->
<% end %>
